package com.learn.springmvc4.advice;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.context.request.WebRequest;

import java.util.HashMap;
import java.util.Map;

/**
 * 定制ControllerAdvice
 * Created by xuxiaobao on 2017/8/4.
 */
@ControllerAdvice
public class ExceptionHandlerAdvice {

    @ExceptionHandler(value = Exception.class)
    public Object exception(Exception exception, WebRequest request) {
        Map<Object, Object> map = new HashMap<Object, Object>();
        map.put("error", exception.getMessage());
        return map;
    }
}
